using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;

namespace yWriter6
{
	[DesignerGenerated]
	public class frmImportOutline : Form
	{
		private IContainer components;

		[CompilerGenerated]
		[AccessedThroughProperty("SplitContainer1")]
		private SplitContainer _SplitContainer1;

		[CompilerGenerated]
		[AccessedThroughProperty("TreeView1")]
		private TreeView _TreeView1;

		[CompilerGenerated]
		[AccessedThroughProperty("txtMain")]
		private RichTextBox _txtMain;

		[CompilerGenerated]
		[AccessedThroughProperty("txtDesc")]
		private RichTextBox _txtDesc;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdOkay")]
		private Button _cmdOkay;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdPreview")]
		private Button _cmdPreview;

		[CompilerGenerated]
		[AccessedThroughProperty("ToolTip1")]
		private ToolTip _ToolTip1;

		[CompilerGenerated]
		[AccessedThroughProperty("TabControl1")]
		private TabControl _TabControl1;

		[CompilerGenerated]
		[AccessedThroughProperty("TabPage1")]
		private TabPage _TabPage1;

		[CompilerGenerated]
		[AccessedThroughProperty("TabPage2")]
		private TabPage _TabPage2;

		[CompilerGenerated]
		[AccessedThroughProperty("TextBox1")]
		private TextBox _TextBox1;

		[CompilerGenerated]
		[AccessedThroughProperty("Splitter1")]
		private Splitter _Splitter1;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdCancel")]
		private Button _cmdCancel;

		[CompilerGenerated]
		[AccessedThroughProperty("TabPage3")]
		private TabPage _TabPage3;

		[CompilerGenerated]
		[AccessedThroughProperty("listErrors")]
		private ListBox _listErrors;

		private bool DidPreview;

		public bool Cancelled;

		[field: AccessedThroughProperty("SplitContainer1")]
		internal virtual SplitContainer SplitContainer1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		internal virtual TreeView TreeView1
		{
			[CompilerGenerated]
			get
			{
				return _TreeView1;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				TreeNodeMouseClickEventHandler value2 = TreeView1_NodeMouseClick;
				TreeView treeView = _TreeView1;
				if (treeView != null)
				{
					treeView.NodeMouseClick -= value2;
				}
				_TreeView1 = value;
				treeView = _TreeView1;
				if (treeView != null)
				{
					treeView.NodeMouseClick += value2;
				}
			}
		}

		internal virtual RichTextBox txtMain
		{
			[CompilerGenerated]
			get
			{
				return _txtMain;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = txtMain_TextChanged;
				RichTextBox txtMain = _txtMain;
				if (txtMain != null)
				{
					txtMain.TextChanged -= value2;
				}
				_txtMain = value;
				txtMain = _txtMain;
				if (txtMain != null)
				{
					txtMain.TextChanged += value2;
				}
			}
		}

		[field: AccessedThroughProperty("txtDesc")]
		internal virtual RichTextBox txtDesc
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		internal virtual Button cmdOkay
		{
			[CompilerGenerated]
			get
			{
				return _cmdOkay;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdOkay_Click;
				Button cmdOkay = _cmdOkay;
				if (cmdOkay != null)
				{
					cmdOkay.Click -= value2;
				}
				_cmdOkay = value;
				cmdOkay = _cmdOkay;
				if (cmdOkay != null)
				{
					cmdOkay.Click += value2;
				}
			}
		}

		internal virtual Button cmdPreview
		{
			[CompilerGenerated]
			get
			{
				return _cmdPreview;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdPreview_Click;
				Button cmdPreview = _cmdPreview;
				if (cmdPreview != null)
				{
					cmdPreview.Click -= value2;
				}
				_cmdPreview = value;
				cmdPreview = _cmdPreview;
				if (cmdPreview != null)
				{
					cmdPreview.Click += value2;
				}
			}
		}

		[field: AccessedThroughProperty("ToolTip1")]
		internal virtual ToolTip ToolTip1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("TabControl1")]
		internal virtual TabControl TabControl1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("TabPage1")]
		internal virtual TabPage TabPage1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("TabPage2")]
		internal virtual TabPage TabPage2
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("TextBox1")]
		internal virtual TextBox TextBox1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("Splitter1")]
		internal virtual Splitter Splitter1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		internal virtual Button cmdCancel
		{
			[CompilerGenerated]
			get
			{
				return _cmdCancel;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdCancel_Click;
				Button cmdCancel = _cmdCancel;
				if (cmdCancel != null)
				{
					cmdCancel.Click -= value2;
				}
				_cmdCancel = value;
				cmdCancel = _cmdCancel;
				if (cmdCancel != null)
				{
					cmdCancel.Click += value2;
				}
			}
		}

		[field: AccessedThroughProperty("TabPage3")]
		internal virtual TabPage TabPage3
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("listErrors")]
		internal virtual ListBox listErrors
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		public frmImportOutline()
		{
			base.FormClosing += frmImportOutline_FormClosing;
			InitializeComponent();
		}

		[DebuggerNonUserCode]
		protected override void Dispose(bool disposing)
		{
			try
			{
				if (disposing && components != null)
				{
					components.Dispose();
				}
			}
			finally
			{
				base.Dispose(disposing);
			}
		}

		[System.Diagnostics.DebuggerStepThrough]
		private void InitializeComponent()
		{
			components = new System.ComponentModel.Container();
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(yWriter6.frmImportOutline));
			SplitContainer1 = new System.Windows.Forms.SplitContainer();
			TreeView1 = new System.Windows.Forms.TreeView();
			txtMain = new System.Windows.Forms.RichTextBox();
			txtDesc = new System.Windows.Forms.RichTextBox();
			cmdOkay = new System.Windows.Forms.Button();
			cmdPreview = new System.Windows.Forms.Button();
			ToolTip1 = new System.Windows.Forms.ToolTip(components);
			TabControl1 = new System.Windows.Forms.TabControl();
			TabPage1 = new System.Windows.Forms.TabPage();
			Splitter1 = new System.Windows.Forms.Splitter();
			TabPage2 = new System.Windows.Forms.TabPage();
			TextBox1 = new System.Windows.Forms.TextBox();
			TabPage3 = new System.Windows.Forms.TabPage();
			listErrors = new System.Windows.Forms.ListBox();
			cmdCancel = new System.Windows.Forms.Button();
			SplitContainer1.Panel1.SuspendLayout();
			SplitContainer1.Panel2.SuspendLayout();
			SplitContainer1.SuspendLayout();
			TabControl1.SuspendLayout();
			TabPage1.SuspendLayout();
			TabPage2.SuspendLayout();
			TabPage3.SuspendLayout();
			SuspendLayout();
			SplitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
			SplitContainer1.Location = new System.Drawing.Point(3, 3);
			SplitContainer1.Name = "SplitContainer1";
			SplitContainer1.Panel1.Controls.Add(TreeView1);
			SplitContainer1.Panel2.Controls.Add(txtMain);
			SplitContainer1.Size = new System.Drawing.Size(649, 278);
			SplitContainer1.SplitterDistance = 216;
			SplitContainer1.TabIndex = 0;
			TreeView1.Dock = System.Windows.Forms.DockStyle.Fill;
			TreeView1.Location = new System.Drawing.Point(0, 0);
			TreeView1.Name = "TreeView1";
			TreeView1.Size = new System.Drawing.Size(216, 278);
			TreeView1.TabIndex = 0;
			txtMain.Dock = System.Windows.Forms.DockStyle.Fill;
			txtMain.Location = new System.Drawing.Point(0, 0);
			txtMain.Name = "txtMain";
			txtMain.Size = new System.Drawing.Size(429, 278);
			txtMain.TabIndex = 1;
			txtMain.Text = "";
			ToolTip1.SetToolTip(txtMain, "Paste your outline here");
			txtDesc.Dock = System.Windows.Forms.DockStyle.Bottom;
			txtDesc.Location = new System.Drawing.Point(3, 286);
			txtDesc.Name = "txtDesc";
			txtDesc.Size = new System.Drawing.Size(649, 113);
			txtDesc.TabIndex = 1;
			txtDesc.Text = "";
			ToolTip1.SetToolTip(txtDesc, "Read only! Change text in your outline, not here.");
			cmdOkay.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			cmdOkay.Enabled = false;
			cmdOkay.Location = new System.Drawing.Point(575, 451);
			cmdOkay.Name = "cmdOkay";
			cmdOkay.Size = new System.Drawing.Size(96, 32);
			cmdOkay.TabIndex = 2;
			cmdOkay.Text = "OK";
			cmdOkay.UseVisualStyleBackColor = true;
			cmdPreview.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			cmdPreview.Location = new System.Drawing.Point(438, 451);
			cmdPreview.Name = "cmdPreview";
			cmdPreview.Size = new System.Drawing.Size(102, 32);
			cmdPreview.TabIndex = 2;
			cmdPreview.Text = "Preview";
			cmdPreview.UseVisualStyleBackColor = true;
			TabControl1.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right);
			TabControl1.Controls.Add(TabPage1);
			TabControl1.Controls.Add(TabPage2);
			TabControl1.Controls.Add(TabPage3);
			TabControl1.Location = new System.Drawing.Point(12, 12);
			TabControl1.Name = "TabControl1";
			TabControl1.SelectedIndex = 0;
			TabControl1.Size = new System.Drawing.Size(663, 431);
			TabControl1.TabIndex = 3;
			TabPage1.Controls.Add(SplitContainer1);
			TabPage1.Controls.Add(Splitter1);
			TabPage1.Controls.Add(txtDesc);
			TabPage1.Location = new System.Drawing.Point(4, 25);
			TabPage1.Name = "TabPage1";
			TabPage1.Padding = new System.Windows.Forms.Padding(3);
			TabPage1.Size = new System.Drawing.Size(655, 402);
			TabPage1.TabIndex = 0;
			TabPage1.Text = "Outline";
			TabPage1.UseVisualStyleBackColor = true;
			Splitter1.Dock = System.Windows.Forms.DockStyle.Bottom;
			Splitter1.Location = new System.Drawing.Point(3, 281);
			Splitter1.Name = "Splitter1";
			Splitter1.Size = new System.Drawing.Size(649, 5);
			Splitter1.TabIndex = 1;
			Splitter1.TabStop = false;
			TabPage2.Controls.Add(TextBox1);
			TabPage2.Location = new System.Drawing.Point(4, 25);
			TabPage2.Name = "TabPage2";
			TabPage2.Padding = new System.Windows.Forms.Padding(3);
			TabPage2.Size = new System.Drawing.Size(655, 402);
			TabPage2.TabIndex = 1;
			TabPage2.Text = "Help";
			TabPage2.UseVisualStyleBackColor = true;
			TextBox1.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right);
			TextBox1.Location = new System.Drawing.Point(6, 6);
			TextBox1.Multiline = true;
			TextBox1.Name = "TextBox1";
			TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			TextBox1.Size = new System.Drawing.Size(643, 390);
			TextBox1.TabIndex = 0;
			TextBox1.Text = resources.GetString("TextBox1.Text");
			TabPage3.Controls.Add(listErrors);
			TabPage3.Location = new System.Drawing.Point(4, 25);
			TabPage3.Name = "TabPage3";
			TabPage3.Padding = new System.Windows.Forms.Padding(3);
			TabPage3.Size = new System.Drawing.Size(655, 402);
			TabPage3.TabIndex = 2;
			TabPage3.Text = "Errors";
			TabPage3.UseVisualStyleBackColor = true;
			listErrors.Dock = System.Windows.Forms.DockStyle.Fill;
			listErrors.FormattingEnabled = true;
			listErrors.ItemHeight = 16;
			listErrors.Location = new System.Drawing.Point(3, 3);
			listErrors.Name = "listErrors";
			listErrors.Size = new System.Drawing.Size(649, 388);
			listErrors.TabIndex = 0;
			cmdCancel.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			cmdCancel.Location = new System.Drawing.Point(12, 451);
			cmdCancel.Name = "cmdCancel";
			cmdCancel.Size = new System.Drawing.Size(75, 32);
			cmdCancel.TabIndex = 2;
			cmdCancel.Text = "Cancel";
			cmdCancel.UseVisualStyleBackColor = true;
			base.AutoScaleDimensions = new System.Drawing.SizeF(8f, 16f);
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			base.ClientSize = new System.Drawing.Size(681, 495);
			base.Controls.Add(TabControl1);
			base.Controls.Add(cmdPreview);
			base.Controls.Add(cmdCancel);
			base.Controls.Add(cmdOkay);
			base.Name = "frmImportOutline";
			Text = "Import Outline";
			SplitContainer1.Panel1.ResumeLayout(false);
			SplitContainer1.Panel2.ResumeLayout(false);
			SplitContainer1.ResumeLayout(false);
			TabControl1.ResumeLayout(false);
			TabPage1.ResumeLayout(false);
			TabPage2.ResumeLayout(false);
			TabPage2.PerformLayout();
			TabPage3.ResumeLayout(false);
			ResumeLayout(false);
		}

		private void txtMain_TextChanged(object sender, EventArgs e)
		{
			cmdOkay.Enabled = false;
			DidPreview = false;
		}

		private void cmdCancel_Click(object sender, EventArgs e)
		{
			Cancelled = true;
			Hide();
		}

		private void cmdPreview_Click(object sender, EventArgs e)
		{
			Preview();
		}

		private void cmdOkay_Click(object sender, EventArgs e)
		{
			if (!DidPreview)
			{
				Interaction.MsgBox("You must preview your outline before applying it to the project");
				return;
			}
			Cancelled = false;
			Hide();
		}

		private void Preview()
		{
			listErrors.Items.Clear();
			TreeView1.Nodes.Clear();
			string text = txtMain.Text;
			if (!text.Contains("[") & !text.Contains("]"))
			{
				Interaction.MsgBox("Invalid outline. Please see the instructions on the Help tab");
				return;
			}
			text = clsShared.cText.CRLF2LF(text);
			string[] array = Strings.Split(text, "\n");
			TreeNode treeNode = null;
			TreeNode treeNode2 = TreeView1.Nodes.Add("Project");
			TreeNode treeNode3 = treeNode2;
			string[] array2 = array;
			bool flag = default(bool);
			foreach (string text2 in array2)
			{
				if (Operators.CompareString(text2.Trim(), "", TextCompare: false) == 0)
				{
					continue;
				}
				if (text2.ToLower().StartsWith("[chapter]"))
				{
					treeNode = treeNode2.Nodes.Add(Strings.Replace(text2, "[chapter]", "").Trim());
					treeNode.Tag = "";
					treeNode3 = treeNode;
					flag = true;
				}
				else if (text2.ToLower().StartsWith("[scene]"))
				{
					if (!flag)
					{
						listErrors.Items.Add("[scene] appeared before first chapter");
						continue;
					}
					treeNode = treeNode3.Nodes.Add(Strings.Replace(text2, "[scene]", "").Trim());
					treeNode.Tag = "";
				}
				else if (text2.ToLower().StartsWith("[desc]"))
				{
					try
					{
						treeNode.Tag = Strings.Replace(text2, "[desc]", "").Trim();
					}
					catch (Exception ex)
					{
						ProjectData.SetProjectError(ex);
						Exception ex2 = ex;
						listErrors.Items.Add("[desc] line appeared before first chapter");
						ProjectData.ClearProjectError();
					}
				}
				else
				{
					listErrors.Items.Add("Line does not start with [chapter] or [scene] or [desc]:");
					listErrors.Items.Add(text2);
				}
			}
			if (listErrors.Items.Count > 0)
			{
				Interaction.MsgBox(Conversions.ToString(listErrors.Items.Count) + " error(s) in your outline. See the Errors tab for details.");
				return;
			}
			TreeView1.ExpandAll();
			DidPreview = true;
			cmdOkay.Enabled = true;
		}

		private void TreeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
		{
			try
			{
				txtDesc.Text = Conversions.ToString(e.Node.Tag);
			}
			catch (Exception ex)
			{
				ProjectData.SetProjectError(ex);
				Exception ex2 = ex;
				ProjectData.ClearProjectError();
			}
		}

		private void frmImportOutline_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (e.CloseReason == CloseReason.UserClosing)
			{
				Cancelled = true;
			}
		}
	}
}
